package com.baidu.structure.widgets;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RelativeLayout;

import com.baidu.structure.R;

/**
 * Created by sunmo on 2016/10/23.
 */
public class BottomNav extends RelativeLayout {
    private RadioButton rbOne;
    private RadioButton rbTwo;
    private RadioButton rbThree;
    private RadioButton rbFour;
    private OnBottomNavSelectedListener mListener;

    public static final int NAV_BOTTOM_ONE=0;
    public static final int NAV_BOTTOM_TWO=1;
    public static final int NAV_BOTTOM_THREE=2;
    public static final int NAV_BOTTOM_FOUR=3;
    public BottomNav(Context context) {
        super(context);
        initView(context);
    }

    private void initView(Context context) {
        View v= View.inflate(context,R.layout.nav_bottom,this);
        rbOne = (RadioButton) v.findViewById(R.id.rbOne);
        rbTwo = (RadioButton) v.findViewById(R.id.rbTwo);
        rbThree = (RadioButton) v.findViewById(R.id.rbThree);
        rbFour = (RadioButton) v.findViewById(R.id.rbFour);

        rbOne.setChecked(true);

        rbOne.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mListener.onBottomNavClick(NAV_BOTTOM_ONE);
            }
        });
        rbTwo.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mListener.onBottomNavClick(NAV_BOTTOM_TWO);
            }
        });
        rbThree.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mListener.onBottomNavClick(NAV_BOTTOM_THREE);
            }
        });
        rbFour.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mListener.onBottomNavClick(NAV_BOTTOM_FOUR);
            }
        });
    }

    public BottomNav(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public BottomNav(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public BottomNav(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    //bottom selected listener
    public void setOnBottomNavSelectedListener(OnBottomNavSelectedListener mListener){
        this.mListener=mListener;
    }
    public interface OnBottomNavSelectedListener {
        void onBottomNavClick(int index);
    }
}
